<?php
namespace Admin\Models\device;

use Admin\Models\BaseModel;
use Admin\Models\sys\XhsysUserTch;
use Admin\Models\user\XhsysUserstud;

class XhsysAccountdevicelocked extends BaseModel
{

    /**
     *
     * @var integer
     * @Primary
     * @Identity
     * @Column(type="integer", length=20, nullable=false)
     */
    public $iADLId;
    public $sNewDevice;
    public $iNewUserId;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iUserId;

    /**
     *
     * @var string
     * @Column(type="string", length=30, nullable=true)
     */
    public $sLogonName;

    /**
     *
     * @var string
     * @Column(type="string", length=50, nullable=true)
     */
    public $sDeviceNumber;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tCreateDate;

    /**
     *
     * @var integer
     * @Column(type="integer", length=20, nullable=true)
     */
    public $iLastModifyUserId;

    /**
     *
     * @var string
     * @Column(type="string", nullable=true)
     */
    public $tLastModifyDate;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    public $bDelete;

    /**
     *
     * @var string
     * @Column(type="string", length=30, nullable=true)
     */
    public $sIP;

    /**
     *
     * @var string
     * @Column(type="string", length=30, nullable=true)
     */
    public $sMac;

    /**
     *
     * @var string
     * @Column(type="string", length=30, nullable=true)
     */
    public $sModel;

    /**
     *
     * @var string
     * @Column(type="string", length=50, nullable=true)
     */
    public $sImei;

    /**
     *
     * @var integer
     * @Column(type="integer", length=11, nullable=true)
     */
    public $iImport;

    /**
     *
     * @var integer
     * @Column(type="integer", length=4, nullable=true)
     */
    public $iSourceType;

    /**
     *
     * @var string
     * @Column(type="string", length=255, nullable=true)
     */
    public $sSourceId;

    /**
     *
     * @var string
     * @Column(type="string", length=100, nullable=true)
     */
    public $sOsDisplay;

    /**
     *
     * @var string
     * @Column(type="string", length=100, nullable=true)
     */
    public $sOsVersion;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHSys_AccountDeviceLocked';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhsysAccountdevicelocked[]|XhsysAccountdevicelocked
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhsysAccountdevicelocked
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 删除前重置学生表认证码可使用
     *
     * @return bool
     *
     * create by ck 20180508
     * modify by ck 20180903
     */
    public function beforeDelete()
    {
        $stud = XhsysUserstud::findFirst($this->iUserId);
        if ($stud && $stud->bAuthUseful != 1) {
            $stud->bAuthUseful = 1;
            $stud->save();
        }
        $tch = XhsysUserTch::findFirst("iUserId = '{$this->iUserId}'");
        if ($tch && $tch->bAuthUseful != 1) {
            $tch->bAuthUseful = 1;
            $tch->save();
        }
        return true;
    }
}
